package com.wusuowei.security.common.security;


import com.wusuowei.security.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.List;

//@Service
public class MyUserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        SysUser sysUser = sysUserService.getByUsername(username);
//        if (sysUser == null) {
//            throw new UsernameNotFoundException("用户名或者密码错误！");
//        } else if ("1".equals(sysUser.getStatus())) {
//            throw new UserCountLockException("该用户账号被封禁，具体请联系管理员！");
//        }
//        return new User(sysUser.getUsername(), sysUser.getPassword(), getUserAuthority(sysUser.getId()));
        return null;
    }

    public List<GrantedAuthority> getUserAuthority(Long userId) {
//        //  格式ROLE_admin,ROLE_common,system:user:resetPwd,system:role:delete,system:user:list,system:menu:query,system:menu:list,system:menu:add,system:user:delete,system:role:list,system:role:menu,system:user:edit,system:user:query,system:role:edit,system:user:add,system:user:role,system:menu:delete,system:role:add,system:role:query,system:menu:edit
//        String authority = sysUserService.getUserAuthorityInfo(userId);
//        return AuthorityUtils.commaSeparatedStringToAuthorityList(authority);
        return null;
    }
}
